/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package utilities;

import GUI.MainFunction;
import GUI.OptionMessage;
import GUI.ViewStaffForm;
import connection.ManLabConnection;
import entities.StaffDetail;
import java.sql.ResultSet;
import java.util.ArrayList;

/**
 *
 * @author VietLH
 */
public class StaffManage {
    private ArrayList<StaffDetail> staffList;
    private ManLabConnection cnn;
    private ResultSet rs;
    private String qry;
    private MainFunction main;
    private OptionMessage optionMessage;
    private SimpleDateFormatter fDate;
    private ValidateInput vi;

    public StaffManage(ArrayList<StaffDetail> staffList, MainFunction main) {
        this.staffList = staffList;
        this.cnn = new ManLabConnection();
        this.main = main;
        this.vi=new ValidateInput();
        this.fDate=new SimpleDateFormatter();
    }
    
    public void viewStaffDetail(StaffDetail staff){
        ViewStaffForm vsf=new ViewStaffForm(main, true);
        vsf.setLblAddressDtl(staff.getStaffAddress());
        vsf.setLblDOBDtl(fDate.convertDateToString(staff.getStaffDOB()));
        vsf.setLblDOJDtl(fDate.convertDateToString(staff.getStaffDOJ()));
        vsf.setLblEduQualDtl(staff.getStaffEduQual());
        vsf.setLblGenderDtl(staff.isStaffGender());
        vsf.setLblStaffNameDtl(staff.toString());
        vsf.setLblUsernameDtl(staff.getStaffUsername());
        vsf.setLblTechSkillDtl(staff.getStaffTechSkill());
        vsf.setLblPhoneDtl(staff.getStaffPhone());
        vsf.setVisible(true);
    }
    public boolean addNewStaff(StaffDetail sd){
        cnn.createConnection();
        String gender="";
        if(sd.isStaffGender()){
            gender="1";
        }
        else{
            gender="0";
        }
        qry="insert into StaffDetail values('"+vi.convertSpecialCharacters(sd.getStaffFName())+"','"
                +vi.convertSpecialCharacters(sd.getStaffLName())
                +"','"+fDate.convertDateToString(sd.getStaffDOJ())+"','"+vi.convertSpecialCharacters(sd.getStaffAddress())+"','"
                +sd.getStaffPhone()
                +"',"+gender+",'"+fDate.convertDateToString(sd.getStaffDOB())+"','"
                +vi.convertSpecialCharacters(sd.getStaffEduQual())+"','"
                +vi.convertSpecialCharacters(sd.getStaffTechSkill())+"','"+sd.getStaffPassword()+"','')";
        boolean pass=cnn.executeQuery(qry);
        if(pass){
            staffList.add(sd);
            return true;
        }else{
            return false;
        }
    }
    private boolean editStaff(StaffDetail sd){
        return false;
    }
}
